export default {
	namespaced: true,
	state() {
		return {
			address: JSON.parse(uni.getStorageSync('address') || '{}'),
			token: uni.getStorageSync('token') || '',
			// 用户的基本信息
			userInfo: JSON.parse(uni.getStorageSync('userInfo') || '{}'),
			// 重定向的指定页面
			redirectInfo: null
		}
	},
	mutations: {
		updateAddress(state, address) {
			state.address = address
			this.commit('user/saveAddressToStorage')
		},
		saveAddressToStorage(state) {
			uni.setStorageSync('address', JSON.stringify(state.address))
		},
		updateUserInfo(state, userInfo) {
			state.userInfo = Object.assign({}, state.userInfo, userInfo)
			this.commit('user/saveUserInfoToStorage')
			console.log('更新用户信息成功!');
		},
		saveUserInfoToStorage(state) {
			uni.setStorageSync('userInfo', JSON.stringify(state.userInfo))
		},
		updateUserToken(state, token) {
			state.token = JSON.stringify(token)
			this.commit('user/saveUserTokenToStorage')
			console.log('更新token成功!');
		},
		saveUserTokenToStorage(state) {
			uni.setStorageSync('token', state.token)
		},
		updateRedirectInfo(state, info) {
			state.redirectInfo = info
			console.log('修改了重定向地址:', info);
		}
	},

}